package com.heima.common.exception;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;


//@RestControllerAdvice
@Slf4j
public class ExcepitionHandler {

    @ExceptionHandler(CostumExcepition.class)
    @ResponseBody
    public ResponseResult CostumExcetion(CostumExcepition e){
        log.error("自定义错误提示{}",e.getStackTrace());
        return ResponseResult.errorResult(e.getAppHttpCodeEnum());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseResult exception(Exception e){
        log.error("未知错误提示{}",e.getStackTrace(),"详细错误",e.getMessage());
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

}
